﻿using System.Collections;
using FlowCanvas;
using FlowCanvas.Nodes;
using NodeCanvas.Framework;
using ParadoxNotion.Design;

namespace Yoozoo.Gameplay.Liberty.Nodes
{
    [Category("Ggame")]
    public class OpenCloseAreaUI : LatentActionNodeBase
    {
        public override bool allowRoutineQueueing { get { return false; } }

        public IEnumerator Invoke(bool isOpen)
        {
             var areaTrigger = parentNode.graphAgent.transform.GetComponentInParent<BlueprintColliderTrigger>();
             if (areaTrigger!=null)
             {
                 if (isOpen)
                 {
                     BlueprintUtils.OpenCloseUI(true, "", areaTrigger.areaId.ToString());
                     yield return new UnityEngine.WaitUntil(() => BlueprintUtils.UIIsShowing(""));
                 }
                 else
                 {
                     BlueprintUtils.OpenCloseUI(false, "", areaTrigger.areaId.ToString());
                     yield return null;
                 }
             }
             else
             {
                 yield break;
             }
        }

        protected override void OnRegisterDerivedPorts(FlowNode node)
        {
            var p1 = node.AddValueInput<bool>(parameters[0].Name);
            node.AddFlowInput("In", (f) => { Begin(Invoke(p1.value), f); });
        }
    }
}